class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        ListNode new_head;
        ListNode *p, *q;
        p = &new_head;
        q = p;
        new_head.next = head;
        for(int i = 0; i <= n; i++) q = q->next;
        while(q){
            q = q->next;
            p = p->next;
        }
        ListNode *temp;
        temp = p->next;
        p->next = p->next->next;
        delete(temp);
        return new_head.next;
    }
};